<?php
class profilemodel
{
		var $db;
		var $base;
		function profilemodel(&$base)
		{
			$this->base = $base;
			$this->db = $base->db;
		}
		function update($row)
		{
			$uid = $_SESSION['user_id'];
			$result = $this->db->fetch_first("SELECT * FROM ".AM_DBTABLEPRE."profiles WHERE uid={$uid}");
			if(!$result)
			{
				$sql = 'INSERT INTO '.AM_DBTABLEPRE.'profiles SET uid='.$uid.',';
				foreach($row as $key=>$value)
				{
					$sql.="$key".'=\''."$value".'\',';
				}
				$sql = substr($sql,0,-1);
				return $this->db->query($sql);
			}
			else
			{
				$sql = 'UPDATE '.AM_DBTABLEPRE.'profiles SET ';
				foreach($row as $key=>$value)
				{
					$sql.="$key".'=\''."$value".'\',';
				}
				$sql = substr($sql,0,-1);
				$sql.="WHERE uid={$uid}";
				return $this->db->query($sql);
			}
		}
		function profiledata($uid)
		{
			$result = $this->db->fetch_first("SELECT * FROM ".AM_DBTABLEPRE."profiles WHERE uid={$uid}");
			return $result;
		}
}
?>